$(document).ready(function() {
	// 设置输入框的提示
	$('a.hide').click(function() {
		$(".cart").toggle("slow");
	});
	
	//监听支付方式radio
	$(":radio").click(function() {
		$("input:checked").attr("checked",false);
		$(this).attr("checked",true);
		//alert($("input:checked").val());
	});
	
	$("#sure").click(function() {
		var payWay = $("input:checked").val().trim();
		if(payWay=="alipay"){
			window.location.href=$(this).attr("rel");
		}else{
			var userName  = $("#userName").html().trim();
			var toAddr = $("input#AddressTextBox").val().trim();
			var toUser =userName +" ["+$("input#PhoneNumTextBox").val().trim()+ "]";
			var toTime = $("input#MoreTextBox").val().trim();
			var isPaid = "false";
			//alert(userName+"--"+toAddr+"---"+toUser+"--"+toTime);
			saveOrder(userName, toAddr, toUser, toTime, isPaid);
		}
	});
});

function saveOrder(userName,toAddr,toUser,toTime,isPaid){
	$.ajax({
		type : "POST",
		url : "servlet/OrderServlet",
		data : "action=saveOrder&userName="+userName+"&toAddr="+toAddr+"&toUser="+toUser+"&toTime="+toTime+"&isPaid="+isPaid,
		success : function(result) {
			var result= result.trim();
			if(result=="failed"){
				alert("亲~~~你的订单提交失败了哦");
			}else {
				window.location.href="orderSuccess.jsp?orderNo="+result;
			}
		}
	});
}